/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.scrumpmt.web;

import java.util.List;
import java.util.logging.Level;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.scrumpmt.domain.Sprint;
import org.scrumpmt.ejb.SprintFacade;


/**
 *
 * @author aljiru
 */
@ManagedBean
@RequestScoped
public class SprintsProductoBean extends BasicBean {

    private List<Sprint> sprints;
    private String productoId;
    private String sprintId;
    private SprintFacade sprintFacade = lookupSprintFacade();
    
    
    /**
     * Creates a new instance of SprintsProductoBean
     */
    public SprintsProductoBean() {
        FacesContext context = FacesContext.getCurrentInstance();
        ProductoSeleccionadoBean productoBean = (ProductoSeleccionadoBean) context.getApplication().evaluateExpressionGet(context, "#{productoSeleccionadoBean}", ProductoSeleccionadoBean.class);
        productoId = productoBean.getProductoActual();
        sprintId = productoBean.getSprintActual();
        
        sprints = sprintFacade.findByProyecto(productoId);
    }

    public String getProductoId() {
        return productoId;
    }

    public void setProductoId(String productoId) {
        this.productoId = productoId;
    }

    public String getSprintId() {
        return sprintId;
    }

    public void setSprintId(String sprintId) {
        this.sprintId = sprintId;
    }

    public List<Sprint> getSprints() {
        return sprints;
    }

    public void setSprints(List<Sprint> sprints) {
        this.sprints = sprints;
    }
    
    private SprintFacade lookupSprintFacade() {
        try {
            Context c = new InitialContext();
            return (SprintFacade) c.lookup("java:global/ScrumPMT/ScrumPMT-ejb/SprintFacade!org.scrumpmt.ejb.SprintFacade");
        } catch (NamingException ne) {
            log.log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
